//
//  TXYResponseData.m
//  FunnyVideo
//
//  Created by 李鑫 on 15/8/28.
//  Copyright © 2015年 NewEggTech. All rights reserved.
//

#import "TXYResponseData.h"

/**
 @property (nonatomic,strong) NSString   *access_url;
 @property (nonatomic,strong) NSString   *biz_attr;
 @property (nonatomic,assign) NSUInteger filelen;
 @property (nonatomic,assign) NSUInteger filesize;
 @property (nonatomic,assign) time_t ctime;
 @property (nonatomic,strong) NSString   *name;
 @property (nonatomic,assign) NSUInteger video_play_time;
 @property (nonatomic,strong) NSString   *video_title;
 */
@implementation TXYResponseVideoInfo
- (id)initWithDictionary:(NSDictionary *)dic{
    self = [super init];
    
    if(self)
    {
        @try {
            self.access_url = dic[@"access_url"];
            self.biz_attr = dic[@"biz_attr"];
            self.filelen = dic[@"filelen"];
            self.filesize = dic[@"filesize"];
            NSString *ctimeStr = dic[@"ctime"];
            self.ctime = [[NSDate dateWithTimeIntervalSince1970:[ctimeStr integerValue]] descriptionWithLocale:[NSLocale systemLocale]];
            self.name = dic[@"name"];
            self.sha = dic[@"sha"];
            self.video_play_time = dic[@"video_play_time"];
            self.video_title = dic[@"video_title"];
            self.video_desc = dic[@"video_desc"];
        }
        @catch (NSException *exception) {
            //显示alert
            //提交到服务器
            NSLog(@"TXYResponseVideoInfo 数据解析异常");
        }
        @finally {

        }
        
        
    }
    
    return self;
}

@end

@interface NSArray (TXYVideoInfoTrans)
- (NSArray *)arrayWithTXYVideoInfos:(NSArray *)videos;
@end

@implementation NSArray (TXYVideoInfoTrans)
- (NSArray *)arrayWithTXYVideoInfos:(NSArray *)videos{
    NSMutableArray *infos = [[NSMutableArray alloc] init];
    
    for(NSDictionary *info in videos)
    {
        TXYResponseVideoInfo *v_info = [[TXYResponseVideoInfo alloc] initWithDictionary:info];
        
        [infos addObject:v_info];
    }
    
    return [NSArray arrayWithArray:infos];
}
@end

@implementation TXYResponseData

- (id)initWithDictionary:(NSDictionary *)dic{
    self = [super init];
    
    if(self)
    {
        @try {
            self.context = dic[@"context"];
            self.dircount = [dic[@"dircount"] integerValue];
            self.filecount = [dic[@"filecount"] integerValue];
            self.has_more = [dic[@"has_more"] boolValue];
            self.infos = [dic[@"infos"] arrayWithTXYVideoInfos:dic[@"infos"]];
        }
        @catch (NSException *exception) {
            //显示alert
            //提交到服务器
            NSLog(@"TXYResponseData 数据解析异常");
        }
        @finally {

        }
    }
    
    return self;
}

- (NSArray *)getVideoInfos{
    
    return self.infos;
}
@end
